local longyin = fk.CreateSkill {
  name = "SP_heg__longyin",
}

Fk:loadTranslationTable{
  ["SP_heg__longyin"] = "龙吟",
  [":SP_heg__longyin"] = "一名与你势力相同的角色于其出牌阶段内使用【杀】时，你可以弃一张手牌令此【杀】不计入次数，若此【杀】为黑色，此技能于本回合内失效。",

  ["#SP_heg__longyin-invoke"] = "龙吟：你可以弃置一张手牌令 %dest 的【杀】不计入次数限制",
  ["@@SP_heg__longyin_lose-turn"] = "龙吟 技能失效",

  ["$SP_heg__longyin1"] = "父斩敌将，吾侍左右。",
  ["$SP_heg__longyin2"] = "龙刃既出，袭营慑敌。",
}

local H = require "packages.ol_hegemony.util"

longyin:addEffect(fk.CardUsing, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(longyin.name) and target.phase == Player.Play and
      data.card.trueName == "slash" and not player:isKongcheng() and H.compareKingdomWith(target, player)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local card = room:askToDiscard(player, {
      min_num = 1,
      max_num = 1,
      include_equip = false,
      skill_name = longyin.name,
      cancelable = true,
      prompt = "#SP_heg__longyin-invoke::" .. target.id,
      skip = true,
    })
    if #card > 0 then
      event:setCostData(self, {tos = {target}, cards = card})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(event:getCostData(self).cards, longyin.name, player, player)
    if not data.extraUse then
      target:addCardUseHistory(data.card.trueName, -1)
      data.extraUse = true
    end
    if data.card.color == Card.Black then
      room:setPlayerMark(player, "@@SP_heg__longyin_lose-turn", 1)
      room:invalidateSkill(player, longyin.name, "-turn")
    end
  end,
})

return longyin
